package com.ruoyi.stat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stat.domain.DistributionStat;
import com.ruoyi.stat.service.IDistributionStatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销统计信息Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/ruoyi/stat")
public class DistributionStatController extends BaseController
{
    @Autowired
    private IDistributionStatService distributionStatService;

    /**
     * 查询分销统计信息列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:stat:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributionStat distributionStat)
    {
        startPage();
        List<DistributionStat> list = distributionStatService.selectDistributionStatList(distributionStat);
        return getDataTable(list);
    }

    /**
     * 导出分销统计信息列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:stat:export')")
    @Log(title = "分销统计信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributionStat distributionStat)
    {
        List<DistributionStat> list = distributionStatService.selectDistributionStatList(distributionStat);
        ExcelUtil<DistributionStat> util = new ExcelUtil<DistributionStat>(DistributionStat.class);
        util.exportExcel(response, list, "分销统计信息数据");
    }

    /**
     * 获取分销统计信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:stat:query')")
    @GetMapping(value = "/{statId}")
    public AjaxResult getInfo(@PathVariable("statId") Long statId)
    {
        return success(distributionStatService.selectDistributionStatByStatId(statId));
    }

    /**
     * 新增分销统计信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:stat:add')")
    @Log(title = "分销统计信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DistributionStat distributionStat)
    {
        return toAjax(distributionStatService.insertDistributionStat(distributionStat));
    }

    /**
     * 修改分销统计信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:stat:edit')")
    @Log(title = "分销统计信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DistributionStat distributionStat)
    {
        return toAjax(distributionStatService.updateDistributionStat(distributionStat));
    }

    /**
     * 删除分销统计信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:stat:remove')")
    @Log(title = "分销统计信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{statIds}")
    public AjaxResult remove(@PathVariable Long[] statIds)
    {
        return toAjax(distributionStatService.deleteDistributionStatByStatIds(statIds));
    }
}
